package com.wedu.modules.dss.controller;

import com.wedu.common.utils.PageUtils;
import com.wedu.common.utils.R;
import com.wedu.modules.dss.entity.MaintenanceRecordsEntity;
import com.wedu.modules.dss.entity.MaintenanceWarningEntity;
import com.wedu.modules.dss.service.DeviceInformationService;
import com.wedu.modules.dss.service.MaintenanceRecordsService;
import com.wedu.modules.dss.service.MaintenanceWarningService;
import com.wedu.modules.sys.controller.AbstractController;
import com.wedu.modules.sys.entity.SysUserEntity;
import com.wedu.modules.sys.service.SysUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("dss/maintenanceRecords")
public class MaintenanceRecordsController extends AbstractController {
    @Autowired
    private SysUserService sysUserService;

    @Autowired
    private MaintenanceRecordsService maintenanceRecordsService;

    /**
     *查看表中信息*/
    @GetMapping("/list")
    @RequiresPermissions("dss:records:list")
    public R list(@RequestParam Map<String,Object> map){
        PageUtils pageUtils = maintenanceRecordsService.queryPageRecord(map);
        R r = R.ok();
        r.put("page",pageUtils);
//        r.put("maintenancePlan",maintenancePlan);
        return r;
    }

    @GetMapping("/info/{deviceId}")
    @RequiresPermissions("dss:records:info")
    public R info(@PathVariable("deviceId") String deviceId){
        MaintenanceRecordsEntity maintenanceRecordsEntity = maintenanceRecordsService.getByDeviceId(deviceId);
//        DeviceInformationEntity deviceInformationEntity = deviceInformationService.getById(deviceId);
        R r = R.ok();
        r.put("maintenanceRecords",maintenanceRecordsEntity);
//        r.put("deviceInformationEntity",deviceInformationEntity);
        return r;
    }

    /**
     * 删除*/
    @PostMapping("/deleted")
    @RequiresPermissions("dss:records:deleted")
    public R delete(@RequestBody Long[] ids){
        maintenanceRecordsService.deleteddevice(ids);

        return R.ok();
    }

//    /**
//     * 将用户id和用户名称存入map*/
//    @GetMapping("/userList")
//    @RequiresPermissions("dss:records:list")
//    public R userList(){
//        List<SysUserEntity> userEntityList = sysUserService.getById()
//    }

//    /**
//     * 添加*/
//    @PostMapping("/save")
//    @RequiresPermissions("dss:records:save")
//    public R save(@RequestBody MaintenanceRecordsEntity maintenanceRecordsEntity){
//        maintenanceRecordsEntity.setCreateTime(new Date());
//        maintenanceRecordsEntity.setCreateBy(getUserId());
//        maintenanceRecordsEntity.setUserId(getUserId());
//        R r = maintenanceRecordsService.savedevice(maintenanceRecordsEntity);
//        return r;
//    }
//
//    @PostMapping("/update")
//    @RequiresPermissions("dss:records:update")
//    public R update(@RequestBody MaintenanceRecordsEntity maintenanceRecordsEntity) {
//        maintenanceRecordsEntity.setUpdateTime(new Date());
//        maintenanceRecordsEntity.setUpdateBy(getUserId());
//        maintenanceRecordsService.updatedevice(maintenanceRecordsEntity);
//        return R.ok();
//    }

}
